package com.example.myui.activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.example.myui.R;
import com.example.myui.customview.CircleProgressView;
import com.example.myui.widget.MyProgressBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class CustomViewActivity extends AppCompatActivity {

    private Unbinder bind;
    @BindView(R.id.circleprogressview)
    CircleProgressView circleprogressview;

    @BindView(R.id.pb4)
    MyProgressBar pb4;

    private static final String TAG = CustomViewActivity.class.getSimpleName();
    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            int what = msg.what;
            switch (what) {
                case 1:
                    int progress = pb4.getProgress();

                    if (progress <= 100) {
                        progress++;
                        pb4.setProgress(progress);

                        mHandler.sendEmptyMessageDelayed(1, 100);

                    } else {
                        Log.i(TAG, "handleMessage: " + "100___________________________");
                    }

                    break;
                default:
                    break;
            }

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom_view);
        bind = ButterKnife.bind(this);
        circleprogressview.setProgress(15);
        circleprogressview.setBackgroundColor(Color.RED);
        circleprogressview.setColor(Color.YELLOW);
        circleprogressview.setBackgroundProgressBarWidth(10);
        circleprogressview.setProgressBarWidth(10);
        circleprogressview.setProgress(50);

        mHandler.post(new Runnable() {
            @Override
            public void run() {
                Message message = mHandler.obtainMessage(1);
                mHandler.sendMessage(message);
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        bind.unbind();
    }
}
